package com.example.lock.mapper;

import com.example.lock.entity.CommodityDetails;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @Description: 商品详情 db
 * @Author: mingtian
 * @CreateDate: 2020/12/11 14:58
 * @Version: 1.0
 */
public interface CommodityDetailsMapper {

    /**
     * 扣库存
     *
     * @return
     */
    @Update("update  commodity_details set stock = stock-1 where id=#{commodityId}")
    int reduceInventory(Long commodityId);

    /**
     * 根据 id 查询
     *
     * @param commodityId
     * @return
     */
    @Select("select * from commodity_details where id=#{commodityId}")
    CommodityDetails getCommodityDetails(Long commodityId);

    /**
     * 行锁扣库存
     *
     * @param commodityId
     * @return
     */
    @Update("update  commodity_details set stock = stock-1 where id=#{commodityId} and stock>0")
    int reduceInventory2(Long commodityId);
}
